package com.dimples.dd.system.mapper;

import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.mybatis.core.mapper.BaseMapperX;
import com.dimples.dd.mybatis.core.query.LambdaQueryWrapperX;
import com.dimples.dd.system.model.entity.SystemSmsChannelDO;
import com.dimples.dd.system.model.query.SmsChannelPageQuery;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SystemSmsChannelMapper extends BaseMapperX<SystemSmsChannelDO> {

    /**
     * 分页查询短信渠道
     *
     * @param pageQuery 分页查询参数
     * @return PageResult
     */
    default PageResult<SystemSmsChannelDO> selectPage(SmsChannelPageQuery pageQuery) {
        return selectPage(pageQuery, new LambdaQueryWrapperX<SystemSmsChannelDO>()
                .likeIfPresent(SystemSmsChannelDO::getSignature, pageQuery.getSignature())
                .eqIfPresent(SystemSmsChannelDO::getStatus, pageQuery.getStatus())
                .betweenIfPresent(SystemSmsChannelDO::getCreateTime, pageQuery.getCreateTime())
                .orderByDesc(SystemSmsChannelDO::getId));
    }

    /**
     * 获得短信渠道下拉列表
     *
     * @return List
     */
    default List<SystemSmsChannelDO> listSmsChannelOptions() {
        return selectList(new LambdaQueryWrapperX<SystemSmsChannelDO>()
                .select(SystemSmsChannelDO::getId, SystemSmsChannelDO::getSignature, SystemSmsChannelDO::getCode));
    }
}